package com.zl.smartmall.library.po;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 订单详情页数据
 * @author 陈希然
 *
 */
public class OrderDetailInfo {
	
	private double money;// 订单金额总额(包含运费)
	private double goldToMoney;//金豆抵扣的钱
	private int orderStatus;// 订单状态，0未支付，1支付成功，2已发货，4完成(签收)，5已失效(过期未支付)，6订单取消
	private int payType;// 支付方式，0 支付宝；1 微信；2 网银；3 货到付款
	private int isReturn;//是否退换货，0否，1退货，2换货
	private int returnStatus;//退换货审核状态；0非退换货，1审核中，2审核通过处理中，3审核完成订单正常(驳回推换货),4退换货完成(货品已经发送给用
	private int deliveryWay;//自提、货到付款
	private long createTime;// 订单创建时间
	private long lastUpdateTime;// 订单最后一次改动时间
	private String orderCode;// 订单号
	private String remarks;
	private String storeHouse;
	private DeliveryAddress deliveryAddress;
	private ExpressInfo expressInfo;
	private InvoiceInfo invoiceInfo;
	private PayInfo payInfos;
	private List<OrderCommoditiesInfo> productInfos;
	private List<CustomerServiceInfo> customerServiceInfos;
	
	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public double getGoldToMoney() {
		return goldToMoney;
	}

	public void setGoldToMoney(double goldToMoney) {
		this.goldToMoney = goldToMoney;
	}

	public int getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(int orderStatus) {
		this.orderStatus = orderStatus;
	}

	public int getPayType() {
		return payType;
	}

	public void setPayType(int payType) {
		this.payType = payType;
	}

	public int getIsReturn() {
		return isReturn;
	}

	public void setIsReturn(int isReturn) {
		this.isReturn = isReturn;
	}

	public int getReturnStatus() {
		return returnStatus;
	}

	public void setReturnStatus(int returnStatus) {
		this.returnStatus = returnStatus;
	}

	public int getDeliveryWay() {
		return deliveryWay;
	}

	public void setDeliveryWay(int deliveryWay) {
		this.deliveryWay = deliveryWay;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public long getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(long lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getStoreHouse() {
		return storeHouse;
	}

	public void setStoreHouse(String storeHouse) {
		this.storeHouse = storeHouse;
	}

	public DeliveryAddress getDeliveryAddress() {
		return deliveryAddress;
	}

	public void setDeliveryAddress(DeliveryAddress deliveryAddress) {
		this.deliveryAddress = deliveryAddress;
	}

	public ExpressInfo getExpressInfo() {
		return expressInfo;
	}

	public void setExpressInfo(ExpressInfo expressInfo) {
		this.expressInfo = expressInfo;
	}

	public InvoiceInfo getInvoiceInfo() {
		return invoiceInfo;
	}

	public void setInvoiceInfo(InvoiceInfo invoiceInfo) {
		this.invoiceInfo = invoiceInfo;
	}

	public PayInfo getPayInfos() {
		return payInfos;
	}

	public void setPayInfos(PayInfo payInfos) {
		this.payInfos = payInfos;
	}

	public List<OrderCommoditiesInfo> getProductInfos() {
		return productInfos;
	}

	public void setProductInfos(List<OrderCommoditiesInfo> productInfos) {
		this.productInfos = productInfos;
	}

	public List<CustomerServiceInfo> getCustomerServiceInfos() {
		return customerServiceInfos;
	}

	public void setCustomerServiceInfos(
			List<CustomerServiceInfo> customerServiceInfos) {
		this.customerServiceInfos = customerServiceInfos;
	}

	public static OrderDetailInfo parse(JSONObject jsonObject) throws JSONException {
		if(jsonObject != null && jsonObject.length() > 0) {
			OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
			orderDetailInfo.orderCode = jsonObject.getString("sn");
	        orderDetailInfo.money = jsonObject.getDouble("money");
	        orderDetailInfo.orderStatus = jsonObject.getInt("ostatus");
	        orderDetailInfo.payType = jsonObject.getInt("payType");
	        orderDetailInfo.createTime = jsonObject.getLong("createTime");
	        orderDetailInfo.lastUpdateTime = jsonObject.getLong("lastUpdateTime");
	        orderDetailInfo.remarks = jsonObject.getString("notes");
	        orderDetailInfo.isReturn = jsonObject.getInt("isReturns");
	        orderDetailInfo.returnStatus = jsonObject.getInt("returnStatus");
	        orderDetailInfo.productInfos = OrderCommoditiesInfo.parse(jsonObject.getJSONArray("product_info"));
	        orderDetailInfo.deliveryAddress = DeliveryAddress.parse(jsonObject.getJSONObject("receiver_info"));
	        orderDetailInfo.invoiceInfo = InvoiceInfo.parse(jsonObject.getJSONObject("invoice_info"));
	        orderDetailInfo.expressInfo = ExpressInfo.parse(jsonObject.getJSONObject("express_info"));
	        orderDetailInfo.payInfos = PayInfo.parse(jsonObject.getJSONObject("pay_info"));
	        orderDetailInfo.customerServiceInfos = CustomerServiceInfo.parse(jsonObject.getJSONArray("CustomerServices"));
	        orderDetailInfo.storeHouse = jsonObject.getString("storehouse");
	        orderDetailInfo.deliveryWay = jsonObject.getInt("cpucbt");
	        JSONObject goldObject = jsonObject.getJSONObject("gold");
	        if(goldObject != null && goldObject.length() > 0) {
	        	orderDetailInfo.goldToMoney = goldObject.getDouble("gold2money");
	        }
			return orderDetailInfo;
		
		}else {
			return null;
		}
	}
}
